//
//  MSEnemySprite.m
//  MagicSword
//
//  Created by Netease on 15/11/20.
//  Copyright © 2015年 Jonear. All rights reserved.
//

#import "MSEnemySprite.h"
#import "MSEnemyInfo.h"

#define SizeAddTemp 10
@implementation MSEnemySprite {
    SKTextureAtlas *_atlas;
    MSEnemyInfo *_enemyInfo;
}

- (id)initWithEnemyInfo:(MSEnemyInfo *)info withSize:(CGSize)size {
    size = CGSizeMake(size.width+SizeAddTemp, size.width+SizeAddTemp);
    self = [super initWithColor:[UIColor clearColor] size:size];
    if (self) {
        _atlas = [SKTextureAtlas atlasNamed:@"enemy_thrumb"];
        _enemyInfo = info;
        
        SKTexture *texture = [_atlas textureNamed:info.mapImage];
        [self setTexture:texture];
        
        NSMutableArray *textures = [[NSMutableArray alloc] init];
        for (int i=1; i<=3; i++) {
            SKTexture *texture = [_atlas textureNamed:[NSString stringWithFormat:@"%@_%d", info.mapImage, i]];
            [textures addObject:texture];
        }
        SKAction *imageAction = [SKAction animateWithTextures:textures timePerFrame:0.3];
        [self runAction:[SKAction repeatAction:imageAction count:INT16_MAX]];
    }

    return self;
}

- (MSEnemyInfo *)enemyInfo {
    return _enemyInfo;
}

@end
